@(originRepository: Option[gitbucket.core.service.RepositoryService.RepositoryInfo],
  members: List[(String, String)],
  groupNames: List[String],
  repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@gitbucket.core.html.main(s"${repository.owner}/${repository.name}", Some(repository)) {
  @gitbucket.core.html.menu("fork", repository){
    <h1 class="body-title">
      Forked repositories
      @if(context.loginAccount.isEmpty){
        <a href="@context.path/signin?redirect=@helpers.urlEncode(s"${context.path}/${repository.owner}/${repository.name}")" class="btn btn-success">Fork</a>
      } else {
        @if(groupNames.isEmpty) {
          <a id="fork-link" href="javascript:void(0);" class="btn btn-success">Fork</a>
        } else {
          <a href="@context.path/@repository.owner/@repository.name/fork" class="btn btn-success" rel="facebox">Fork</a>
        }
      }
    </h1>
    @if(context.loginAccount.isDefined && groupNames.isEmpty){
      <form id="fork-form" method="post" action="@context.path/@repository.owner/@repository.name/fork" style="display: none;">
        <input type="hidden" name="account" value="@context.loginAccount.get.userName"/>
      </form>
    }
    <div class="block">
      @if(originRepository.isDefined){
        @helpers.avatar(originRepository.get.owner, 20)
        <span@if(repository.owner == originRepository.get.owner){ class="highlight"}>
          <a href="@helpers.url(originRepository.get.owner)">@originRepository.get.owner</a> / <a href="@context.path/@originRepository.get.owner/@originRepository.get.name">@originRepository.get.name</a>
        </span>
      } else {
        @helpers.avatar(repository.repository.originUserName.get, 20)
        <span class="highlight">
          @repository.repository.originUserName / @repository.repository.originRepositoryName
        </span>
      }
      (origin)
    </div>
    @members.map { case (owner, name) =>
      <div class="block">
        @helpers.avatar(owner, 20)
        <span@if(repository.owner == owner){ class="highlight"}>
          <a href="@helpers.url(owner)">@owner</a> / <a href="@context.path/@owner/@name">@name</a>
        </span>
      </div>
    }
  }
}
<script>
$(function(){
  $('a[rel*=facebox]').facebox({
    'loadingImage': '@helpers.assets/vendors/facebox/loading.gif',
    'closeImage': '@helpers.assets/vendors/facebox/closelabel.png'
  });

  $(document).on("click", ".js-fork-owner-select-target", function() {
    if (!$(this).hasClass("disabled")) {
      var account = $(this).text().replace("@@", "");
      $("#account").val(account);
      $("#fork").submit();
    }
  });

  @if(context.loginAccount.isDefined){
  $(document).on("click", "a#fork-link", function(e) {
    e.preventDefault();
    $('#fork-form').submit();
  });
  }
});
</script>
